package com.educhains.web.ctrl.frontend;

import com.educhains.module.demo.service.DemoService;
import com.educhains.module.demo.vo.Demo;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author YuRun
 * @since 2017年8月15日
 */
@Controller
public class DemoCtrl {

    private static final Logger logger = LogManager.getLogger(DemoCtrl.class);

    @Autowired
    private DemoService demoService = null;

    @RequestMapping(value = "/demo", method = RequestMethod.GET)
    public String index(HttpServletRequest request) {
        logger.info("log4j demo");

        String pageNum = request.getParameter("p") == null ? "1" : request.getParameter("p");//获取页码，默认1
        request.setAttribute("page", demoService.showByPage(Integer.valueOf(pageNum)));
        //     List<Demo> demoList = demoService.getDemoList();
        return "frontend/demo/demo";
    }

    @RequestMapping(value = "/chat", method = RequestMethod.GET)
    public String chat(HttpServletRequest request) {
        return "frontend/demo/chat";
    }
}
